<template>
	<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="80px" label-position="top">
		<el-row :gutter="20">
			<el-col :span="24">
				<el-form-item label="渠道来源" prop="avatar">
					<el-radio-group v-model="form.type" @change="gType">
						<el-radio v-model="form.type" label='1'>微信</el-radio>
						<el-radio v-model="form.type" label='2'>抖音</el-radio>
						<el-radio v-model="form.type" label='3'>快手</el-radio>
					</el-radio-group>
				</el-form-item>
			</el-col>
			<el-col :span="24">
				<el-form-item label="手机扫码二维码" prop="avatar">
										<qrcode-vue
											id="qrcodeBox"
											:size="qrcodeVue.size"
											:value="qrcodeVue.value"
											:logo="qrcodeVue.logo"
											:bgColor="qrcodeVue.bgColor"
											:fgColor="qrcodeVue.fgColor"
										></qrcode-vue>
				</el-form-item>
			</el-col>
		</el-row>
	</el-form>
</template>

<script>
// import config from "@/config";
import qrcodeVue from 'qrcode.vue'
	export default {
		props: {
			mode: { type: String, default: "add" }
		},
		components: {
			qrcodeVue,

		},
		data() {
			return {
				//表单数据
				form: {
					type:"1"
				},

				qrcodeVue: {
					size: 120,
					bgColor: "#fff",
					fgColor: "#000",
					value: "",	//二维码地址
					// logo: "https://www.baidu.com/img/flexible/logo/pc/result@2.png"	//logo图片
				}

			}
		},
		mounted() {
			if(this.mode != 'add'){
				this.rules.password = []
				this.rules.password2 = []
			}
			this.getGroup()
			this.gType()
		},
		methods: {
			//加载树数据
			async getGroup(){
				var res = await this.$API.role.select.get();
				this.groups = res.data;
			},
			gType(){
				let that = this
				this.$API.user.addQrcode.get({type:this.form.type}).then((res)=>{

                   if(res.code==200){
					   console.log(res.data)
					   that.qrcodeVue.value = res.data
				   }else{
					   this.$message.error(res.msg)
				   }
				})

			},
			//表单提交方法
			submit(callback){
				this.$refs.dialogForm.validate((valid) => {
					if (valid) {
						callback(this.form)
					}else{
						return false;
					}
				})
			},
			//表单注入数据
			setData(data){
				this.form.id = data.id
				this.form.userName = data.userName
				this.form.avatar = data.avatar
				this.form.name = data.name
				this.form.group = data.group

				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				//Object.assign(this.form, data)
			}
		}
	}
</script>

<style>
</style>
